/**
 * Created by ydz on 15/11/9.
 */
//    时间
var jsonData = {'legend':['听力', '语法','阅读'],'listening':[320, 302, 309,133],'reading':[220, 182, 191,564],'grammar':[120, 132, 101,566]};
var timechartoption = {
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    legend: {
        data:['听力', '语法','阅读']
    },
    toolbox: {
        show : true,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    calculable : true,
    xAxis : [
        {
            type : 'value'
        }
    ],
    yAxis : [
        {
            type : 'category',
            data : ['我的时间','最小时间','平均时间','最大时间']
        }
    ],
    series : [
        {
            name:'听力',
            type:'bar',
            stack: '总量',
            itemStyle : { normal: {barBorderRadius:[4, 4, 4, 4],label : {show: true, position: 'insideRight'}}},
            data:jsonData.listening
        },
        {
            name:'语法',
            type:'bar',
            stack: '总量',
            itemStyle : { normal: {barBorderRadius:[4, 4, 4, 4],label : {show: true, position: 'insideRight'}}},
            data:jsonData.grammar
        },
        {
            name:'阅读',
            type:'bar',
            stack: '总量',
            itemStyle : { normal: {barBorderRadius:[4, 4, 4, 4],label : {show: true, position: 'insideRight'}}},
            data:jsonData.reading
        }
    ]
};
var timeChart = echarts.init(document.getElementById('main-timechart'));
// 为echarts对象加载数据
timeChart.setOption(timechartoption);
window.onresize = timeChart.resize;


var dataStyle = {
    normal: {
        label: {show:false},
        labelLine: {show:false}
    }
};
var placeHolderStyle = {
    normal : {
        color: 'rgba(0,0,0,0)',
        label: {show:false},
        labelLine: {show:false}
    },
    emphasis : {
        color: 'rgba(0,0,0,0)'
    }
};
var pieoption = {
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        show:false,
        orient : 'vertical',
        x : 'left',
        data:['1','2','3','4','5','6','7','8','9','10'],
        selectedMode:false
    },
    toolbox: {
        show : false,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            magicType : {
                show: true,
                type: ['pie', 'funnel']
            },
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    calculable : false,
    series : [
        {
            name:'平均时长',
            type:'pie',
            selectedMode: 'single',
            radius : [30, 50],

            // for funnel
            x: '20%',
            width: '40%',
            funnelAlign: 'right',
            max: 1548,
            itemStyle : dataStyle,
            data:[
                {value:335, name:'1'},
                {value:679, name:'2'},
                {value:500, name:'3'},
                {value:335, name:'4'},
                {value:679, name:'5'},
                {value:335, name:'6'},
                {value:679, name:'7'},
                {value:335, name:'8'},
                {
                    value:800,
                    name:'invisible',
                    itemStyle : placeHolderStyle
                }
            ]
        },
        {
            name:'我的考试时长',
            type:'pie',
            radius : [60, 80],

            // for funnel
            x: '60%',
            width: '35%',
            funnelAlign: 'left',
            max: 1048,
            data:[
                {value:335, name:'1'},
                {value:310, name:'2'},
                {value:234, name:'3'},
                {value:135, name:'4'},
                {value:1000, name:'5'},
                {value:251, name:'6'},
                {value:147, name:'7'},
                {value:102, name:'8'},
                {
                    value:500,
                    name:'invisible',
                    itemStyle : placeHolderStyle
                }
            ]
        }
    ]
};

var mainpiechart = document.getElementById('main-piechart')
var piegrammarchart = echarts.init(document.getElementById('pie-grammar'));
// 为echarts对象加载数据
piegrammarchart.setOption(pieoption);
//window.onresize = piegrammarchart.resize;

var pielisteningchart = echarts.init(document.getElementById('pie-listening'));
// 为echarts对象加载数据
pielisteningchart.setOption(pieoption);
//window.onresize = pielisteningchart.resize;

var piereadingchart = echarts.init(document.getElementById('pie-reading'));
// 为echarts对象加载数据
piereadingchart.setOption(pieoption);
//window.onresize = piereadingchart.resize;
//window.onresize = mainpiechart.resize;


var lineoption = {
    tooltip : {
        trigger: 'axis'
    },
    toolbox: {
        show : false,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    //legend: {
    //    selectedMode:false
    //},
    dataRange: {
        show:false,
        min: 99,
        max: 100,
        orient: 'horizontal',
        y: 'top',
        //text:['高','低'],           // 文本，默认为数值文本
        color:['green','red'],
        splitNumber: 5
    },
    xAxis : [
        {
            type : 'category',
            boundaryGap : false,
            data : function (){
                var list = [];
                for (var i = 1; i <= 36; i++) {
                    list.push( i);
                }
                return list;
            }()
        },
        {
            type : 'value',
            scale : true,
            splitNumber: 35,
            axisLabel: {show:false},
            splitLine: {show:false}
        }
    ],
    yAxis : [
        {
            type : 'value'
        },
        {
            type : 'value'
        }
    ],
    animation: false,
    series : [
        {
            name:'结果',
            type:'scatter',
            tooltip : {
                trigger: 'item',
                formatter : function (params) {
                    //return  params.value[0] + '<br/>'
                    //    + params.seriesName + ' : '
                    //    + params.value[1] + ', '
                    //    + params.value[2];
                    var flag = params.value[2];
                    if(flag == 99){
                        return "错误！"
                    }else{
                        return "正确！"
                    }
                }
            },
            yAxisIndex:1,
            xAxisIndex:1,
            symbol: 'circle',
            symbolSize: 10,
            data: [
                [1, 10, 99],
                [2, 10, 99],
                [3, 10, 99],
                [4, 10, 99],
                [5, 10, 99],
                [6, 10, 99],
                [7, 10, 99],
                [8, 10, 99],
                [9, 10, 99],
                [10, 10, 99],
                [11, 10, 99],
                [12, 10, 99],
                [13, 10, 99],
                [14, 10, 99],
                [15, 10, 99],
                [16, 10, 99],
                [17, 10, 99],
                [18, 10, 99],
                [19, 10, 99],
                [20, 10, 99],
                [21, 10, 99],
                [22, 10, 99],
                [23, 10, 99],
                [24, 10, 99],
                [25, 10, 99],
                [26, 10, 99],
                [27, 10, 99],
                [28, 10, 99],
                [29, 10, 99],
                [30, 10, 99],
                [31, 10, 99],
                [32, 10, 99],
                [33, 10, 99],
                [34, 10, 99],
                [35, 10, 99],
                [36, 10, 99]
            ]
        },
        {
            name:'难度',
            type:'line',
            data:[1,2,3,4,5,1,1,2,3,4,5,1,1,2,3,4,5,1,1,2,3,4,5,1,1,2,3,4,5,1,1,2,3,4,5,1]
        },
        {
            name:'整体准确率',
            type:'line',
            data:[0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94,0.98,0.96,0.94]
        }
    ]
};
var linechart = echarts.init(document.getElementById('main-linechart'));
// 为echarts对象加载数据
linechart.setOption(lineoption);
window.onresize = linechart.resize;


var boxoption = {
    tooltip : {
        trigger: 'axis',
        formatter: function (params) {
            var res =params[0].seriesName + ' ' + params[0].name;
            res += '<br/>  最低得分 : ' + params[0].value[0] + '  排名第25% 对应的得分 : ' + params[0].value[3];
            res += '<br/>  最高得分 : ' + params[0].value[1] + '  排名第75% 对应的得分 : ' + params[0].value[2];
            return res;
        }
    },
    color:[
        '#ff7f50', '#87cefa', '#da70d6', '#32cd32', '#6495ed',
        '#ff69b4', '#ba55d3', '#cd5c5c', '#ffa500', '#40e0d0',
        '#1e90ff', '#ff6347', '#7b68ee', '#00fa9a', '#ffd700',
        '#6b8e23', '#ff00ff', '#3cb371', '#b8860b', '#30e0e0'
    ],
    toolbox: {
        show : false,
        feature : {
            mark : {show: true},
            dataZoom : {show: true},
            dataView : {show: true, readOnly: false},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    xAxis : [
        {
            type : 'category',
            boundaryGap : true,
            axisTick: {onGap:false},
            splitLine: {show:false},
            data : [
                "总分", "听力", "阅读", "语法"
            ]
        }
    ],
    yAxis : [
        {
            type : 'value',
            scale:true,
            boundaryGap: [0.01, 0.01],
            min:0,
            max:100
        }
    ],
    series : [
        {
            name:'',
            type:'k',
            barMaxWidth: 80,
            itemStyle: {
                normal: {
                    color: 'white',           // 阳线填充颜色
                    color0: 'lightgreen',   // 阴线填充颜色
                    lineStyle: {
                        width: 2,
                        color: 'orange',    // 阳线边框颜色
                        color0: 'green'     // 阴线边框颜色
                    }
                },
                emphasis: {
                    color: 'white',         // 阳线填充颜色
                    color0: 'white'         // 阴线填充颜色
                }
            },
            data:[ // 开盘，收盘，最低，最高
                {
                    value: [5,98,69,76],
                    itemStyle: {
                        normal: {
                            color0: 'orange',         // 阴线填充颜色
                            lineStyle: {
                                width: 2,
                                color0: 'orange'      // 阴线边框颜色
                            }
                        },
                        emphasis: {
                            color0: 'orange'          // 阴线填充颜色
                        }
                    }
                },
                [0,100,45,78],
                [35,99,55,92],
                [22,98,35,88]
            ],
            markPoint : {
                symbol: 'star',
                symbolSize:5,
                itemStyle:{
                    normal:{label:{position:'top'}, color: 'red', }
                },
                data : [
                    {name : '我的分数', value : 58, xAxis: '总分', yAxis: 58},
                    {name : '我的分数', value : 78, xAxis: '听力', yAxis: 78},
                    {name : '我的分数', value : 88, xAxis: '阅读', yAxis: 88},
                    {name : '我的分数', value : 68, xAxis: '语法', yAxis: 68}
                ]
            }
        }
    ]
};
var boxchart = echarts.init(document.getElementById('main-boxlinechart'));
// 为echarts对象加载数据
boxchart.setOption(boxoption);
window.onresize = boxchart.resize;


var matrixoption = {
    title: {
        text: '知识点',
        subtext: '第一题',
        sublink: 'http://e.weibo.com/1341556070/AhQXtjbqh',
        x: 'center',
        y: 'center',
        itemGap: 20,
        textStyle : {
            color : 'rgba(30,144,255,0.8)',
            fontFamily : '微软雅黑',
            fontSize : 15,
            fontWeight : 'bolder'
        }
    },
    tooltip : {
        show: true,
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        show:false,
        orient : 'vertical',
        //x : document.getElementById('matrix-1').offsetWidth / 2,
        y : 45,
        itemGap:12,
        data:['听力','阅读','语法']
    },
    toolbox: {
        show : false,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    series : [
        {
            name:'1',
            type:'pie',
            clockWise:false,
            radius : [75, 90],
            itemStyle : dataStyle,
            data:[
                {
                    value:68,
                    name:'听力'
                },
                {
                    value:32,
                    name:'invisible',
                    itemStyle : placeHolderStyle
                }
            ]
        },
        {
            name:'2',
            type:'pie',
            clockWise:false,
            radius : [55, 70],
            itemStyle : dataStyle,
            data:[
                {
                    value:29,
                    name:'阅读'
                },
                {
                    value:71,
                    name:'invisible',
                    itemStyle : placeHolderStyle
                }
            ]
        },
        {
            name:'3',
            type:'pie',
            clockWise:false,
            radius : [35, 50],
            itemStyle : dataStyle,
            data:[
                {
                    value:3,
                    name:'语法”'
                },
                {
                    value:97,
                    name:'invisible',
                    itemStyle : placeHolderStyle
                }
            ]
        }
    ]
};
var matrixchart = echarts.init(document.getElementById('matrix-1'));
// 为echarts对象加载数据
matrixchart.setOption(matrixoption);
window.onresize = matrixchart.resize;